#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
 
int n, front, rear;
bool v[16777220];
 
struct Map {
    char arr[12];
    int step;
    Map() {
        memset(arr, 0, sizeof(arr));
        step = 0;
    }
    void move(int i) {
        if (i == 0)
            swap(arr[0], arr[1]);
        else if (i == 1) {
            char temp = arr[0];
            for (int i=1; i<n; i++) {
                arr[i-1] = arr[i];
            }
            arr[n-1]  = temp;
        }
        step++;
    }
} start, target, li[200000];
  
// 进制转换
int trans(Map map) {
    int ans = 0;
    for (int i=0; i<n; i++) {
        // 因为该题只有4种选择，因此转换成四进制
        ans *= 4;
        switch (map.arr[i]) {
        case 'T':
            ans += 1;
            break;
        case 'C':
            ans += 2;
            break;
        case 'G':
            ans += 3;
            break;
        }
    }
    return ans;
}
  
int main() {
    while(scanf("%d", &n)!=EOF && n) {
        bool flag = false;
        front = 0, rear = -1;
        memset(v, false, sizeof(v));
        scanf("%s", start.arr);
        scanf("%s", target.arr);
        li[++rear] = start;
        v[trans(start)] = true;
        int tg = trans(target);
  
        if (tg == trans(start)) {
            printf("0\n");
            break;
        }
 
        while(front <= rear) {
            if(flag) break;
            for (int i=0; i<2; i++) {
                Map map = li[front];
                map.move(i);
                if (v[trans(map)])
                    continue;
                if (tg == trans(map)) {
                    printf("%d\n", map.step);
                    flag = true;
                }
                v[trans(map)] = true;
                li[++rear] = map;
            }
            front++;
        }
    }
    return 0;
}